package com.nb.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.nb.dao.SetmealDao;
import com.nb.dao.SetmealDishDao;
import com.nb.domain.Setmeal;
import com.nb.domain.SetmealDish;
import com.nb.dto.SetmealDto;
import com.nb.service.SetmealDishService;
import com.nb.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class SetmealServiceImpl extends ServiceImpl<SetmealDao,Setmeal> implements SetmealService {

    @Autowired
    private SetmealDishService setmealDishService;

   //新增套餐
    @Override
    @Transactional
    public void saveWithDish(SetmealDto setmealDto) {
        //存套餐的基本信息
        this.save(setmealDto);
        //获取套餐所有的菜品
        List<SetmealDish> setmealDishes = setmealDto.getSetmealDishes();
        setmealDishes = setmealDishes.stream().map((item)->{
            item.setSetmealId(setmealDto.getId());
            return item;
        }).collect(Collectors.toList());

        //保存套餐和菜品的相关的信息
        setmealDishService.saveBatch(setmealDishes);

    }


    @Override
    public void removeWithDish(List<Long> ids) {

    }
}
